home *** CD-ROM | disk | FTP | other *** search
- /* Speech.c -- QB code resource for access to MacinTalk routines
- Copyright (C)1988 by William H. Ball for MacTutor™ magazine
-
- Usage: SAY(rate,pitch,string)
- where [rate] is an integer or integer variable
- [pitch] is an integer or integer variable
- [string] is a string variable or string enclosed by quotes.
- for example,
- hefty% = 100 : wimpy% = 300 : fast% = 200 : slow% = 100
- m$ = "Hello there"
- CALL SAY(slow%,hefty%,m$)
- CALL SAY(fast%,wimpy%,m$)
- or
- CALL SAY(100,100,"Hello there")
- CALL SAY(200,300,"Hello there")
-
- Caveats: Can cause bombs of ID 2 or ID 10 if you fail to pass
- the correct number or type of arguments.
- */
-
- #include "Macintalk.h" /* LSC's header */
- #include "BasicLSC.h" /* supplied with QB */
-
- PUBLIC VOID main() /* see QB manual p. 448 */
- {
- SpeechErr err; /* error code */
- SpeechHandle theSpeech; /* pointer to speech */
- Handle spOut; /* speech handle */
-
- INT16 TempFlag,len,type,rate,pitch; /* INT16 == short */
- StringPtr message;
- LIBARGPTR valptr;
-
- SAVEREGS(); /* Save BASIC's A4 and A5 registers */
-
- if ((err = SpeechOn("", &theSpeech)) != noErr) { return; }
-
- if ((type = GetNextLibArg(&valptr,&TempFlag)) != _INTARG) rate = 150;
- else rate = IntegerArg();
- SpeechRate(theSpeech,(int)rate);
-
- if ((type = GetNextLibArg(&valptr,&TempFlag)) != _INTARG) pitch = 95;
- else pitch = IntegerArg();
- SpeechPitch(theSpeech,(int)pitch,Natural);
-
- type = GetNextLibArg(&valptr,&TempFlag);
- if (type != _NULLARG) {
- if (type == _STRGARG) {
- if (TempFlag)
- FreeTempDesc((SDRECPTR)valptr);
- LoadStringDesc((SDRECPTR)valptr,&message,&len);
- spOut = NewHandle(0L); /* allocate handle */
- Reader(theSpeech,message,(long)len,spOut);
- MacinTalk(theSpeech, spOut);
- SpeechOff(theSpeech);
- DisposHandle(spOut);
- }
- }
- RESTREGS(); /* Restore BASIC's A4 and A5 registers */
- }